<?php

namespace App\Http\Controllers;

use Auth;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * @param $role
     * @return mixed
     */
    public function validateUserRole($role){
        return Auth::User()->hasRole($role);
    }

    /**
     * @param $permission
     * @return mixed
     */
    public function validateUserPermission($permission){
        return Auth::User()->can($permission);
    }

    /**
     * @param $permission
     * @return bool|\Illuminate\Http\RedirectResponse
     */
    public function validateUserPermissionRedirect($permission){

        if(!Auth::User()->can($permission)){
            abort(401,"你没有权限");
        }
    }

}
